/*
 * Jenny Ruppen 09-730-391
 * Sebastien Goldberg 08-914-855
 * Henry Raymond 08-928-061
 * Stefan Mussato 09-752-270
 */
 
package ch.uzh.ifi.sopra.gruppe9.game;

import java.util.ArrayList;

/**
 * Class of buying agent cards. Each buying agent card has a unique ID. This class is used by
 * the server and the client. RMI methods on the other hand only use the unique IDs without 
 * transmitting the BuyingAgent objects. Each buying agent card has a color. Use the createDeck()
 * method to create all cards of the game.
 */
public class BuyingAgent {
	
	
	/**
	 * All possible colors of buying agent cards.
	 * Color NONE is for action locations that don't have their color constraint set yet.
	 */
	public enum Color {NONE, BLUE, GREEN, YELLOW, PURPLE, ORANGE};
	
	
	/**
	 * Array used to translate the enum values to integers for RMI methods.
	 */
	private static Color[] enumToIntTranslator = {Color.NONE, Color.BLUE, Color.GREEN, Color.YELLOW, Color.PURPLE, Color.ORANGE}; 
	
	
	/**
	 * Unique ID of card
	 */
	private int id;
	
	
	/**
	 * Color of the buying agent.
	 */
	private Color color;	
	
	
	/**
	 * Constructor: Creates a buying agent card of a color corresponding to its ID.
	 */
	public BuyingAgent(int id) {
		this.id = id;
		if(id < 9) {
			color = Color.BLUE;
		} else if(id < 18) {
			color = Color.GREEN;
		} else if(id < 27) {
			color = Color.YELLOW;
		} else if(id < 36) {
			color = Color.PURPLE;
		} else {
			color = Color.ORANGE;
		}
	}
	
	
	public int getId() {
		return id;
	}
	
	
	public Color getColor() {
		return color;
	}
	
	
	/**
	 * Creates all buying agent cards.
	 */
	public static ArrayList<BuyingAgent> createDeck() {
		
		ArrayList<BuyingAgent> deck = new ArrayList<BuyingAgent>();
		for(int i = 0; i < 45; i++) {
			deck.add(new BuyingAgent(i));
		}
		return deck;
	}
	
	
	/**
	 * Translate color enum to integer for RMI methods
	 */
	public static int enumToInt(Color color) {
		for(int i = 0; i < enumToIntTranslator.length; i++) {
			if(enumToIntTranslator[i] == color) {
				return i;
			}
		}
		return 0;
	}
	
	
	/**
	 * Translate color integer to enum for RMI methods
	 */
	public static Color intToEnum(int integer) {
		return enumToIntTranslator[integer];
	}


}
